Questions
1 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
01 / 45

What is a pseudo-element in CSS?

Understanding Pseudo-Elements in CSS

A pseudo-element in CSS allows you to style specific parts of an element without needing to add extra HTML markup. Common pseudo-elements include ::before, ::after, ::first-letter, and ::first-line.

Key Points
  1. 1

    Pseudo-elements let you style subparts of elements or insert content dynamically.

  2. 2

    They are indicated by a double colon :: to distinguish them from pseudo-classes.

  3. 3

    They do not exist in the DOM; they are virtual elements created for styling purposes.

  4. 4

    Common use cases include decorative content, highlighting the first letter, or adding icons before/after text.

Example: Using ::before and ::first-letter

In this example, ::first-letter enlarges and colors the first letter, while ::before inserts a star before the paragraph text without modifying the HTML.

Best Practices
  1. 1

    Use pseudo-elements to add stylistic content without cluttering HTML.

  2. 2

    Combine with CSS properties like content, color, font-size, and background.

  3. 3

    Avoid using them for interactive elements that require JavaScript functionality.

  4. 4

    Test across browsers to ensure consistent rendering.

Difficulty: 3/10
Topics: pseudo-element syntax, styling before/after content, layout implications

Scenario Questions

0-2 years experience
  1. 1

    How would you add a star icon before every review rating using CSS without changing the HTML?

  2. 2

    What happens if you try to apply a border to a ::before element without setting content: ''?

  3. 3

    You’re trying to style a tooltip with ::after, but it’s not showing up—what are the first three things you’d check?

2-5 years experience
  1. 1

    A designer wants a speech bubble tooltip using ::before and ::after, but it’s breaking on mobile—how would you debug and fix it?

  2. 2

    Your team’s CSS library uses ::before for icons, but now accessibility audits say screen readers are reading the content—what’s the issue and how do you resolve it?

  3. 3

    A button’s ::after hover effect works in Chrome but not Safari—what could be causing this, and how would you investigate?

5-8 years experience
  1. 1

    You’re building a scalable component library with pseudo-elements for decorative elements—how do you balance performance, maintainability, and accessibility across 50+ components?

  2. 2

    A legacy UI uses ::before for visual separators, but now we’re migrating to a CSS-in-JS system—what are the tradeoffs of keeping pseudo-elements vs. switching to divs or SVGs?

  3. 3

    How would you design a responsive navigation indicator using pseudo-elements that works across browsers, supports dark mode, and doesn’t impact layout shift during hydration?

8+ years experience
  1. 1

    Your company’s design system relies heavily on pseudo-elements for UI embellishments—how would you architect a migration plan to reduce CSS complexity and improve render performance at scale?

  2. 2

    Pseudo-elements are used across 20+ product teams for icons and indicators, but inconsistent usage is causing accessibility and testing issues—how do you enforce standards without stifling autonomy?

  3. 3

    We’re considering removing all ::before/::after usage in favor of SVGs for better SSR and CDN caching—what are the long-term maintenance, performance, and developer experience tradeoffs you’d present to leadership?

Follow-up Questions

  • What happens if you forget the content property on a ::before element?
  • Can you style a pseudo-element with JavaScript directly?
  • Why might a ::after element not appear even when the CSS looks correct?